//===================================
//YMC12864-486
//IC:ST7567a I2C
//VDD=3.0V,VLCD=12.0V,1/65DUTY,1/9BIAS
//===================================
#include <reg52.h>
#include <intrins.h>
#include "delay.h"

#define uchar unsigned char
#define uint unsigned int

sbit	res = P1^2;
sbit	sck = P1^1;
sbit	sda	= P1^0;

#include "i2c.h"
#include "isp.h"
#include "contrastAdj.h"
#include "lcd_test2015.h"
#include "image.h"

void init_lcm()
{
		start_i2c();
		sendbyte(0x7e);
		sendbyte(0x80);
	 	sendbyte(0xe2);		//软件复位

		sendbyte(0x80);
		sendbyte(0xa2);		//1/8bias  
		
		sendbyte(0x80);
		sendbyte(0xa1);		//seg反向
		
		sendbyte(0x80);
		sendbyte(0xc0);		//com正向
	
		
	  sendbyte(0x80);//5倍压
	  sendbyte(0xf8);
	
	  sendbyte(0x80);//5倍压
	  sendbyte(0x01);

		sendbyte(0x80);
		sendbyte(0x25);		//RR
		
		sendbyte(0x80);
		sendbyte(ConstrstReg);	//set vop
		sendbyte(0x80);
		sendbyte(contrast);		

		sendbyte(0x80);
		sendbyte(0x2f);

		sendbyte(0x80);
		sendbyte(0x40);

		sendbyte(0x80);
		sendbyte(0xaf);

		sendbyte(0x80);
		sendbyte(0xa4);
		stop_i2c();
}


void icon(unsigned char code *p)
{
	  uchar j;
	  start_i2c();
		sendbyte(0x7e);
	
		sendbyte(0x80); 
		sendbyte(0xb8);
	
    sendbyte(0x80);	
	  sendbyte(0x10);	
	
	  sendbyte(0x80);
	  sendbyte(0x00);
	
	  sendbyte(0x40);
	for(j=0;j<110;j++)
	{	
		 sendbyte(*p++);
	}
	stop_i2c();
}



void main(void)																	   
{
	
	isp_init();
	delay_us(0);
	delay_ms(2);
	delay_ss(0);

	res=0;
	delay_ms(100);
	res=1;
	delay_ms(100);
	init_lcm();
	while(1)
	{	
		line(0xff);icon(image_k);		//图素和点阵部分都全显			
		pauseBig();
		
		
		line(0x11);icon(image_l);	
		pauseSmall();
		line(0x22);icon(image_l);	
		pauseSmall();	
		line(0x44);icon(image_l);	
		pauseSmall();	
		line(0x88);icon(image_l);	
		pauseSmall();
		
		ver(0xff,0x00,0x00,0x00);icon(image_m);pauseSmall();
		ver(0x00,0xff,0x00,0x00);icon(image_m);pauseSmall();
		ver(0x00,0x00,0xff,0x00);icon(image_m);pauseSmall();
		ver(0x00,0x00,0x00,0xff);icon(image_m);pauseSmall();
		
		lcd_image(image_j); icon(image_n);
		pauseBig();
		
		lcd_image(image_f); icon(image_ff);
		pauseBig();
		while(1);
	}
}